package com.zi.experttalk.experttalk.View;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TabHost;
import com.zi.experttalk.experttalk.R;

/**
 * Created by lenovo on 2014/12/9.
 */
public class HomeActivity extends TabActivity {
    private final int TAB_HOME = 0;
    private final int TAB_COUPON = 1;
    private final int TAB_NEARBY = 2;
    private final int TAB_MORE = 4;
    private final int TAB_USER = 3;
    private TabHost home_Tabhost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.home);
        Log.d("main","create");
        home_Tabhost = getTabHost();

//        主页跳转
        Intent main_pageIntent = new Intent(this,Main_pageActivity.class);
//        优惠页面跳转
        Intent couponIntent = new Intent(this,CouponActivity.class);
//        周边页面跳转
        Intent nearIntent = new Intent(this,NearActivity.class);
//        我的信息页面跳转
        Intent userIntent = new Intent(this,UserActivity.class);
//        更多信息页面跳转
        Intent moreIntent = new Intent(this,MoreActicity.class);

        ImageView imageView = new ImageView(this);
//         设置图片填充方式
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setImageResource(R.drawable.tab_home);
        home_Tabhost.addTab(home_Tabhost.newTabSpec(TAB_HOME + "")
                                         .setContent(main_pageIntent)
                                         .setIndicator(imageView));
        imageView = new ImageView(this);
//         设置图片填充方式
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setImageResource(R.drawable.tab_coupon);
        home_Tabhost.addTab(home_Tabhost.newTabSpec(TAB_COUPON + "")
                .setContent(couponIntent)
                .setIndicator(imageView));
        imageView = new ImageView(this);
//         设置图片填充方式
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setImageResource(R.drawable.tab_nearby);
        home_Tabhost.addTab(home_Tabhost.newTabSpec(TAB_NEARBY + "")
                .setContent(nearIntent)
                .setIndicator(imageView));

        imageView = new ImageView(this);
//         设置图片填充方式
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setImageResource(R.drawable.tab_user);
        home_Tabhost.addTab(home_Tabhost.newTabSpec(TAB_USER + "")
                .setContent(userIntent)
                .setIndicator(imageView));

        imageView = new ImageView(this);
//         设置图片填充方式
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setImageResource(R.drawable.tab_more);
        home_Tabhost.addTab(home_Tabhost.newTabSpec(TAB_MORE + "")
                .setContent(moreIntent)
                .setIndicator(imageView));

            getIdonPressed(0);

        home_Tabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                getIdonPressed(Integer.parseInt(tabId));
            }
        });
    }


    public void getIdonPressed(int tabId){
        ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_HOME)).setImageResource(R.drawable.tab_home);
        ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_COUPON)).setImageResource(R.drawable.tab_coupon);
        ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_NEARBY)).setImageResource(R.drawable.tab_nearby);
        ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_USER)).setImageResource(R.drawable.tab_user);
        ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_MORE)).setImageResource(R.drawable.tab_more);


        if (tabId == TAB_HOME) {
            ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_HOME)).setImageResource(R.drawable.tab_home_highlight);
        }
        if (tabId == TAB_COUPON) {
            ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_COUPON)).setImageResource(R.drawable.tab_coupon_highlight);
        }
        if (tabId == TAB_NEARBY) {
            ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_NEARBY)).setImageResource(R.drawable.tab_nearby_highlight);
        }
        if (tabId == TAB_MORE) {
            ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_MORE)).setImageResource(R.drawable.tab_more_highlight);
        }
        if (tabId == TAB_USER) {
            ((ImageView) home_Tabhost.getTabWidget().getChildAt(TAB_USER)).setImageResource(R.drawable.tab_user_highlight);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("main","start");

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("main","restart");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("main","destory");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("main","stop");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("main","pause");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("main","resume");


    }
}
